package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌管理")
@RestController
@RequestMapping(value="/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;




    @Operation(summary = "查询品牌列表")
    @GetMapping("{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page,@PathVariable Integer limit){
       PageInfo<Brand> pageInfo =  brandService.findByPage(page,limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "添加品牌")
    @PostMapping("save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "修改品牌")
    @PutMapping("updateById")
    public Result updateById (@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id) {
        brandService.deleteById(id);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "查找所有品牌")
    @GetMapping("findAllBrand")
    private Result findAllBrand(){
        List<Brand> list = brandService.findAllBrand();
        return Result.build(list, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "根据第三级id查询品牌")
    @GetMapping("findByCategory3Id/{category3Id}")
    public Result findByCategory3Id(@PathVariable Long category3Id){
        List<Brand> list = brandService.findByCategory3Id(category3Id);
        return Result.build(list, ResultCodeEnum.SUCCESS);

    }

}
